﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EpiPoker.DataAccess;

namespace EpiPoker
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            AppFacebookService objFbService = (AppFacebookService)Session["fbService"];

            if (!IsPostBack)
            {
                try
                {
                    Avatar.ImageUrl = objFbService._fbService.GetUserInfo().PictureUrl.ToString();
                }
                catch (Exception ex)
                {
                    Session.Clear();
                    Response.Redirect("./Default.aspx");
                }

                // TEMPORARY
                Avatar.Height = 50;
                Avatar.Width = 50;
                //

                FullName.Text = objFbService._fbService.GetUserInfo().FirstName + ' ' + objFbService._fbService.GetUserInfo().LastName;

                // Portfolio amount
                fbPokerEntities bdd = new fbPokerEntities();

                try
                {
                    T_Portfolio portfolio = DataAccess.Portfolio.GetPortfolioByUserId(long.Parse(objFbService._fbService.UserId));
                    int amount = (int)portfolio.Amount;
                    NbChips.Text = "$ " + amount.ToString();


                    // Number of friends registered in the app
                    System.Collections.ObjectModel.Collection<Facebook.User> listFriendAppUser = objFbService._fbService.GetFriendsAppUsers();
                    NbFriends.Text = listFriendAppUser.Count.ToString();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
    }
}
